﻿/// <reference path="_namespace.js" />
/// <reference path="/ajax/math/Matrix.js"/>
/// <reference path="../BoundingFrustum.js"/>
/// <reference path="/ajax/math/Plane3.js"/>
/*****************************************************************************
Ajaxna library class definition.
Author: krobinson 11/4/2008 6:09:49 PM.
Class:  myAjaxApp.Transform
*****************************************************************************/

$addNamespace("ajax.xna.framework.graphics");
$imports("ajax.math.Matrix");
//-----------------------------------------------------------------------------

// CTransforms Class
ajax.xna.framework.graphics.Transform = function(device)
{///<param name="device" type="ajax.xna.framework.graphics.GraphicsDevice">The graphics device these transforms belong to.</param> 
    this._graphicsDevice = device;
    this._world = new ajax.math.Matrix();
    this._view = new ajax.math.Matrix();
    this._projection = new ajax.math.Matrix();
}
$extend("ajax.xna.framework.graphics.Transform", "");

//-----------------------------------------------------------------------------
ajax.xna.framework.graphics.Transform.prototype =
{
    _graphicsDevice: null,
    _world: ajax.math.Matrix.prototype,
    _view: ajax.math.Matrix.prototype,
    _projection: ajax.math.Matrix.prototype,

    get_graphicsDevice: function()
    {///<value type="ajax.xna.framework.graphics.GraphicsDevice"/>
        return this._graphicsDevice;
    },
    set_graphicsDevice: function(value) { this._graphicsDevice = value; },
    get_world: function()
    {///<value type="ajax.math.Matrix">Gets or sets the world matrix used when rendering.</value>
        return this._world;
    },
    set_world: function(value) { this._world = value; },
    get_view: function()
    {///<value type="ajax.math.Matrix">Gets or sets the view matrix used when rendering.</value>
        return this._view;
    },
    set_view: function(value) { this._view = value; },
    get_projection: function()
    {///<value type="ajax.math.Matrix">Gets or sets the projection matrix used when rendering.</value>    
        return this._projection
    },
    set_projection: function(value)
    {
        this._projection = value;

        // Update the culling frustum used by the graphics device to use this projection matrix.
        //var frustum = ajax.xna.framework.BoundingFrustum.cast(this._graphicsDevice.boundingFrustum);
        var frustum = this._graphicsDevice.boundingFrustum;
        frustum.set_matrix(value);
        // Use the planes generated by the frustum to set the min & max depth on our viewport.
        this._graphicsDevice.viewport.set_minDepth(Math.abs(frustum.get_near().distance));
        this._graphicsDevice.viewport.set_maxDepth(Math.abs(frustum.get_far().distance));
    }
}


// Statics
//-----------------------------------------------------------------------------
ajax.xna.framework.graphics.Transform.cast = function(obj)
{///<returns type="ajax.xna.framework.graphics.Transform"/>
    return obj;
}